<?php
class Wmp_View_Helper_WmpLog extends Zend_View
{
	public function WmpLog($message="---",$priorityname="INFO",$prioritylevel=1)
    {
		$message = Wmp_Lib::curPageURL(). ': '.$message ;
    	$controller = Zend_Controller_Front::getInstance();
		$request	=$controller->getRequest();
		$module		= $request->getModuleName();
        $controller	= $request->getControllerName();
        $action		= $request->getActionName();
        
        $logeduser		= Zend_Auth::getInstance();        
        $username="visitor"; //invité
     	if ($logeduser->hasIdentity()) {
     		$username = $logeduser->getIdentity()->username;     		   
        }
    	$db = Zend_Registry::get('db');    
		$columnMapping = array(	'username' => 'username',
								'userip' => 'userip',
								'module' => 'module',
								'controller' => 'controller',
								'action' => 'action',
								'timestamp' => 'timestamp',
								'message' => 'message',
								'prioritylevel' => 'priority',
								'priorityname' => 'priorityName',
							);
		$writer = new Zend_Log_Writer_Db($db, 'logs', $columnMapping);	
		$logger = new Zend_Log($writer);		
		$logger->setEventItem('username', $username);
		$logger->setEventItem('userip', getenv('REMOTE_ADDR'));
		$logger->setEventItem('module', $module);	
		$logger->setEventItem('controller', $controller);
		$logger->setEventItem('action', $action);			
		$logger->setEventItem('timestamp', time());
		$logger->setEventItem('priorityname', $priorityname);	
		$logger->setEventItem('prioritylevel', $prioritylevel);		
		$logger->info($message);		
    }	
}